
#include <REGX51.H>
#include <INTRINS.H>

sbit _LED_1 = P2^0;

unsigned char _led_data[] = {
	0x01,
	0x02,
	0x04,
	0x08,
	0x10,
	0x20,
	0x40,
	0x80,
};

void delay(unsigned int n)
{
	unsigned int _i = 0, _j = 0;
	for (_i = 0; _i < n; _i++)
	{
		for (_j = 0; _j < 120; _j++);
	}
}

/**
 *
 */
void led()
{
	unsigned int _i = 0;

	for (_i = 0; _i < 4; _i++)
	{
		// P2 = ~ _led_data[_i];
		P2 = ~ (0x01 << _i);
		delay(100);
	}
}

// 共阴 0-9
unsigned char _seg_data[] = {
	0x3F,
	0x06,
	0x5B,
	0x4F,
	0x66,
	0x6D,
	0x7D,
	0x07,
	0x7F,
	0x6F,
};

/**
 * 
 */
void seg()
{
	unsigned int _i = 0;

	for (_i = 0; _i < 10; _i++)
	{
		P3 = _seg_data[_i];
		delay(100);
	}
}

// HELLO
unsigned char _seg_8_data_1[] = {
	0x76,
	0x79,
	0x38,
	0x38,
	0x3F,
};

// 位
unsigned char _seg_8_data_2[] = {
	0x00,
	0x01,
	0x02,
	0x03,
	0x04,
	0x05,
	0x06,
	0x07,
};

/**
 * 
 */
void seg_8()
{
	unsigned int _i = 0;

	for (_i = 0; _i < 10; _i++)
	{
		P1 = _seg_data[_i];
		delay(100);
	}
}

void main()
{	
	while(1)
	{
		seg_8();
		seg();
		// _LED_1 = 0;
		// delay(5);
		// _LED_1 = 1;
		// delay(5);
		led();
	}
}
